/**
    ******************************************************************************
    * @file    redis.c
    * @author  debian
    * @version V1.0.0
    * @date    2020-04-04
    * @brief   简单使用redis
    ******************************************************************************
    * @attention
    *
    *
    ******************************************************************************
    */ 

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <hiredis.h>

// export LD_LIBRARY_PATH="&LD_LIBRARY_PATH:/usr/local/lib"
// gcc redis.c -lhiredis -I/usr/local/include/hiredis/ -o redis

/** @addtogroup DataStruct_Driver
    * @{
    */

/** @addtogroup redis
    * @{
    */

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/


/** @defgroup redis_Exported_Functions redis Exported Functions
    * @{
    */

/** @defgroup redis_Exported_Functions_Group1 Initialization and deinitialization functions
    *  @brief    Initialization and Configuration functions
    *
@verbatim    
    ===============================================================================
                ##### Initialization and deinitialization functions #####
    ===============================================================================
    [..]
        This section provides functions allowing to initialize and de-initialize the redis
        to be ready for use.
 
@endverbatim
    * @{
    */ 

/**
    * @brief  创建redis对象
    * @param  
    * @retval 
    */ 
    int main(int argc, char **argv) 
    {
        redisContext *context = redisConnect("127.0.0.1", 6379);

        if(context == NULL && context->err) {
            if(context) {
                printf("%s \n", context->errstr);
            } else {
                printf("redisConnect error\n");
            }
            exit(EXIT_FAILURE);
        }

        printf("---------- context success -----------\n");

        redisReply *reply = redisCommand(context, "auth ren");
        printf("type : %d\n", reply->type);
        if (reply->type == REDIS_REPLY_STATUS) {
            /*SET str Hello World*/
            printf("auth ok\n");
        }
        freeReplyObject(reply);

        char *key = "chen";
        char *value = "hello world";
        reply = redisCommand(context, "set %s %s", key, value);
        printf("type : %d\n", reply->type);
        if (reply->type == REDIS_REPLY_STATUS) {
            /*SET str Hello World*/
            printf("set %s %s ok\n", key, value);
        }
        freeReplyObject(reply);

        reply = redisCommand(context, "get %s", key);
        if (reply->type == REDIS_REPLY_STRING) {
            /*SET str Hello World*/
            printf("get %s ok\n", reply->str);
            printf("get %d ok\n", reply->len);
        }
        freeReplyObject(reply);

        

        redisFree(context);

        return 0;
    }

/**
    * @brief  销毁redis对象
    * @param  
    * @retval 
    */ 
    
    
/**
    * @}
    */

/** @defgroup redis_Exported_Functions_Group2 operation functions 
    *  @brief   operation functions
    *
@verbatim   
    ===============================================================================
                        ##### operation functions #####
    ===============================================================================
    [..]
        This subsection provides a set of functions allowing to manage the redis.

@endverbatim
    * @{
    */

        /* 操作函数写在这里 */

    /**
    * @}
    */


/**
    * @}
    */

/**
    * @}
    */

/**
    * @}
    */

/************************ (C) 2020 HOME 深圳龙华 *****END OF FILE****/

